#include <bits/stdc++.h>
using namespace std;

int n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    int a = 0, b = 1, c = 1;

    while (n > c) {
        a = b;
        b = c;
        c = a + b;
    }

    cout << min(c - n, n - b);

    return 0;
}